<template>
	<view>
		<view class="cu-card article">
			<view class="cu-item shadow">
				<view class="flex solid-bottom padding justify-between">
					<view class="text-lg">
						<view style="background: #fff;">
							<view class="t-login">
								<u--form labelPosition="left" labelWidth="80" :model="userInfo" :rules="rules"
									ref="uForm">
									<u-form-item label="报到位置" ref="item1" :required="true">
										<u--input disabled clearable v-model="userInfo.location" border="surround">
										</u--input>
									</u-form-item>
									<u-form-item label="司机姓名" prop="driverName" ref="item1" :required="true">
										<u--input type="text" clearable v-model="userInfo.driverName" border="surround">
										</u--input>
									</u-form-item>
									<u-form-item label="手机号码" prop="phoneNum" ref="item1" :required="true">
										<u--input type="number" clearable v-model="userInfo.phoneNum" border="surround">
										</u--input>
									</u-form-item>
									<u-form-item v-if="fieldDisplay.idCard==1" label="身份证号" prop="idCard" ref="item1"
										:required="true">
										<u--input type="idCard" clearable v-model="userInfo.idCard" border="surround">
										</u--input>
									</u-form-item>
									<u-form-item v-if="fieldDisplay.contactCompany==1" label="报备单位"
										prop="contactCompany" borderBottom ref="item1" :required="true">
										<u--input clearable v-model="userInfo.contactCompany" border="surround">
										</u--input>
									</u-form-item>
									<u-form-item v-if="fieldDisplay.contactDept==1" label="报备部门及项目" prop="contactDept"
										borderBottom ref="item1" :required="true">
										<u--input clearable v-model="userInfo.contactDept" border="surround">
										</u--input>
									</u-form-item>
									<u-form-item v-if="fieldDisplay.contactPerson==1" label="联络人" prop="contactPerson"
										borderBottom ref="item1" :required="true">
										<u--input clearable v-model="userInfo.contactPerson" border="surround">
										</u--input>
									</u-form-item>
									<u-form-item v-if="fieldDisplay.contactPhone==1" label="联络方式" prop="contactPhone"
										borderBottom ref="item1" :required="true">
										<u--input clearable v-model="userInfo.contactPhone" border="surround">
										</u--input>
									</u-form-item>

									<u-row style="margin-top: 20px;">
										<u-col span="4">
											<u-button v-if="fieldDisplay.addCarButton==1" type="success" text="添加车辆"
												@click="pagetoVehicle()"></u-button>
											<u-button v-if="fieldDisplay.examinationButton==1" type="success"
												text="司机培训考核" @click="pageto1()"></u-button>
										</u-col>
										<u-col span="4">

										</u-col>
										<u-col span="4">
											<u-button type="primary" text="选择车辆信息" @click="selectCarShow"></u-button>

										</u-col>
									</u-row>
									<view style="margin-top: 80rpx;">
										<u-form-item style="margin-top: -70rpx;" label="车牌颜色" prop="plateColor"
											borderBottom ref="item1" :required="true">
											<u-radio-group :disabled="carDis" @change="plateChange"
												v-model="userInfo.plateColor" iconPlacement="left">
												<u-row>
													<u-col span="6">
														<u-radio name="1" label="黄色"></u-radio>
													</u-col>
													<u-col span="6">
														<u-radio name="0" label="蓝色"></u-radio>
													</u-col>
													<u-col span="6">
														<u-radio name="4" label="绿色"></u-radio>
													</u-col>
												</u-row>
											</u-radio-group>
										</u-form-item>
									</view>
									<u-form-item prop="image" labelPosition="top" border-bottom label="行驶证"
										:required="true">
										<u-upload accept="image" :deletable="!carDis" :fileList="fileList99"
											@afterRead="afterRead" :beforeChoose="beforeChooseColor" @delete="deletePic"
											name="99" multiple :maxCount="1">
										</u-upload>
									</u-form-item>
									<u-form-item label="车牌号" prop="plateNo" borderBottom ref="item1" :required="true">
										<u--input clearable :disabled="carDis" v-model="userInfo.plateNo"
											border="surround">
										</u--input>
									</u-form-item>
									<view @click=getCarType(1)>
										<u-form-item style="margin-top: 70rpx;" label="车辆类型" prop="carType" borderBottom
											:required="true">
											<u--input type="text" readonly clearable v-model="userInfo.carType1"
												border="none">
												<template slot="suffix">
													<u-button v-if="!carDis" size="mini" type="primary" text="点击选择">
													</u-button>
												</template>
											</u--input>
										</u-form-item>
									</view>
									<u-form-item label="VIN识别码" prop="vin" borderBottom :required="true">
										<u--input :disabled="carDis" type="text" clearable v-model="userInfo.vin"
											border="surround">
										</u--input>
									</u-form-item>
									<u-form-item label="车辆品牌型号" prop="carBrandModel" borderBottom :required="true">
										<u--input type="text" :disabled="carDis" clearable
											v-model="userInfo.carBrandModel" border="surround">
										</u--input>
									</u-form-item>

									<view>
										<u-form-item label="发动机号" prop="engineNum" borderBottom :required="true">
											<u--input type="text" :disabled="carDis" clearable @input="handleInput"
												v-model="userInfo.engineNum" border="surround">
											</u--input>
										</u-form-item>
									</view>
									<u-form-item label="注册日期" prop="registerDate" borderBottom :required="true">
										<u--input type="text" readonly clearable v-model="userInfo.registerDate"
											border="none">
											<template slot="suffix">
												<u-button @click="showRegister('1')" v-if="!carDis" size="mini"
													type="primary" text="点击选择"></u-button>
											</template>
										</u--input>
									</u-form-item>
									<view v-if="src&&!carDis&&vinDis" style="margin: 20rpx; color: red;">点击图片更换验证码
									</view>
									<u-image v-if="src&&!carDis&&vinDis" width="100%" height="300rpx" :src="src"
										@click="refreshCaptcha">
									</u-image>
									<u-form-item v-if="!carDis&&vinDis" label="验证码" prop="evnType" borderBottom
										ref="item1" :required="true">
										<u--input clearable v-model="userInfo.captcha" border="surround">
										</u--input>
									</u-form-item>
									<u-button v-if="!carDis&&vinDis" style="margin-top: 30rpx;" type="primary"
										:loading="addLoading" :disabled="addLoading" text="获取排放信息" @click="query">
									</u-button>
									<!-- @click=getCarType(4)s -->
									<view>
										<u-form-item label="排放类型" prop="evnType" borderBottom :required="true">
											<u--input type="text" readonly clearable v-model="userInfo.evnType1"
												border="none">
												<template slot="suffix">
													<!-- <u-button v-if="!carDis" size="mini" type="primary" text="获取排放类型">
													</u-button> -->
												</template>
											</u--input>
										</u-form-item>

									</view>

									<u-form-item label="发动机型号" prop="engineType" borderBottom :required="true">
										<u--input type="text" clearable v-model="userInfo.engineType" border="surround">
										</u--input>

									</u-form-item>
									<u-form-item label="发动机制造商名称" prop="engineManufacturer" borderBottom
										:required="true">
										<u--input type="text" clearable v-model="userInfo.engineManufacturer"
											border="surround">
										</u--input>
									</u-form-item>

									<view style="margin: 20rpx; color: red;">接入全国道路货运车辆公共监管与服务平台(安装北斗）</view>
									<u-form-item label="联网状态" prop="networkingStatus" borderBottom :required="true">
										<u-radio-group :disabled="carDis" v-model="userInfo.networkingStatus"
											iconPlacement="left">
											<u-row>
												<u-col span="8">
													<u-radio name="0" label="未联网"></u-radio>
												</u-col>
												<u-col span="8">
													<u-radio name="1" label="已联网"></u-radio>
												</u-col>
											</u-row>
										</u-radio-group>
									</u-form-item>
									<view @click=getCarType(3)>
										<u-form-item label="使用性质" prop="function" borderBottom :required="true">
											<u--input type="text" readonly clearable v-model="userInfo.function1"
												border="none">
												<template slot="suffix">
													<u-button v-if="!carDis" size="mini" type="primary" text="点击选择">
													</u-button>
												</template>
											</u--input>
										</u-form-item>
									</view>





									<view v-if="fieldDisplay.producedTime==1">
										<u-form-item label="车辆生产日期" prop="producedTime" borderBottom :required="true">
											<u--input type="text" readonly clearable v-model="userInfo.producedTime"
												border="none">
												<template slot="suffix">
													<u-button size="mini" type="primary" @click="showRegister('2')"
														text="点击选择">
													</u-button>
												</template>
											</u--input>
										</u-form-item>
									</view>
									<u-form-item label="运输公司营业执照名称" prop="fleet" borderBottom :required="true">
										<u--input type="text" clearable v-model="userInfo.fleet" border="surround">
										</u--input>
									</u-form-item>
									<view @click=getCarType(2)>
										<u-form-item label="燃料类型" prop="userInfo.fuelType" borderBottom
											:required="true">
											<u--input type="text" readonly clearable v-model="userInfo.fuelType1"
												border="none">
												<template slot="suffix">
													<u-button v-if="!carDis" size="mini" type="primary" text="点击选择">
													</u-button>
												</template>
											</u--input>
										</u-form-item>
									</view>
									<!-- labelWidth="300rpx" -->
									<u-form-item v-if="fieldDisplay.packagingOil==1" label="运输货物类型" labelPosition="top"
										prop="packagingOil" borderBottom :required="true">
										<u-radio-group v-model="userInfo.packagingOil" iconPlacement="left">
											<u-row style="margin-top: 30rpx;">
												<u-col span="8">
													<u-radio name="1" label="包装油业务"></u-radio>
												</u-col>
												<u-col span="8">
													<u-radio name="0" label="非包装油业务"></u-radio>
												</u-col>
											</u-row>
										</u-radio-group>
									</u-form-item>
									<u-form-item v-if="fieldDisplay.leadingEnterprise==1" label="引领性企业"
										prop="leadingEnterprise" borderBottom :required="true">
										<u-radio-group v-model="userInfo.leadingEnterprise" iconPlacement="left"
											@change="radioChangeGoods">
											<u-row>
												<u-col span="8">
													<u-radio name="0" label="否"></u-radio>
												</u-col>
												<u-col span="8">
													<u-radio name="1" label="是"></u-radio>
												</u-col>
											</u-row>
										</u-radio-group>
									</u-form-item>
									<u-form-item label="运输状态" prop="transportStatus" borderBottom :required="true">
										<u-radio-group v-model="userInfo.transportStatus" iconPlacement="left"
											@change="radioChangeGoods">
											<u-row>
												<u-col span="8">
													<u-radio name="0" label="提货"></u-radio>
												</u-col>
												<u-col span="8">
													<u-radio name="1" label="送货"></u-radio>
												</u-col>
											</u-row>
										</u-radio-group>
									</u-form-item>

									<view v-if="fieldDisplay.goods==1" @click=getCarType(5)>
										<u-form-item label="运输货物名称" prop="goods" borderBottom :required="true">
											<u--input type="text" readonly clearable v-model="userInfo.goods"
												border="none">
												<template slot="suffix">
													<u-button size="mini" type="primary" text="点击选择"></u-button>
												</template>
											</u--input>

										</u-form-item>
									</view>
									<u-form-item v-if="fieldDisplay.goods==0" label="运输货物名称" prop="goods" borderBottom
										:required="true">
										<u--input type="text" v-model="userInfo.goods" border="surround">

										</u--input>

									</u-form-item>
									<u-form-item v-if="showRemarks" label="备注" prop="remarks" borderBottom
										:required="true">
										<u--textarea v-model="userInfo.remarks"></u--textarea>
									</u-form-item>
									<u-form-item v-if="fieldDisplay.freightVolume==1" label="运输量(单位:吨)"
										prop="freightVolume" borderBottom :required="true">
										<u--input type="number" clearable v-model="userInfo.freightVolume"
											border="surround">
										</u--input>
									</u-form-item>
									<u-form-item v-if="fieldDisplay.driversLicense==1" prop="image" labelPosition="top"
										border-bottom label="驾驶证" :required="true">
										<u-upload accept="image" :fileList="fileList3" @afterRead="afterRead"
											@delete="deletePic" name="3" multiple :maxCount="1">
										</u-upload>
									</u-form-item>
									<u-form-item labelWidth="220" prop="image" labelPosition="top" border-bottom
										label="环保清单或环保网站查询截图" :required="true">
										<u-upload accept="image" :deletable="!carDis" :fileList="fileList2"
											@afterRead="afterRead" @delete="deletePic" name="2" multiple :maxCount="1">
										</u-upload>
									</u-form-item>
									<view class="repair_class">
										<view class="u-demo-block__content radio_box">
											<view class="u-page__radio-item">
												<u-radio-group v-model="tongyi" style="margin-top: 20px;">
													<view class="repair_redio_box">
														<u-radio name='同意' shape="circle" labelSize="14"
															label="我承诺所提供的“环保信息随车清单”及“行驶证”真实有效，无弄虚作假，并承诺对相应结果承担相应法律责任。">
														</u-radio>
													</view>
												</u-radio-group>
											</view>
										</view>
									</view>

									<u-button style="margin-top: 30rpx;" type="primary" :loading="addLoading"
										:disabled="addLoading" text="登记" @click="addInfo"></u-button>
								</u--form>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>

		<u-modal :show="carShow" showCancelButton width="600rpx" :title="title" @cancel="carShow=false"
			@confirm="carConfirm">
			<scroll-view scroll-y="true" style="height: 650rpx;">
				<view>
					<u-row style="margin-top: 20px;">
						<u-col span="4">
							<u-button v-if="plateList.length>0" type="primary" size="mini"
								style="width: 200rpx;  margin-top: 20rpx;" @click="addCarMessage()">
								新增</u-button>
						</u-col>
						<u-col span="4">

						</u-col>
						<u-col span="4">


						</u-col>
					</u-row>
					<u-row style="margin-top: 20px;">
						<u-col span="8">
							<u--input placeholder="车牌号" v-model="plateNo" suffixIconStyle="color: #909399"></u--input>
						</u-col>
						<u-col span="4">
							<u-button type="primary" size="mini" style="width: 100rpx;  margin-top: 10rpx;"
								@click="getCarPlate">
								查询</u-button>
						</u-col>
					</u-row>
					<u-radio-group placement="column" style="margin-top: 20rpx;">
						<u-radio size="30" iconSize="30" :customStyle="{marginBottom: '8px'}" labelSize="20"
							v-for="(item, index) in plateList" :key="item.id" :label="item.plateNo" :name="item.plateNo"
							@change="radioChange(item)">
							<view style="font-size: 30rpx;">
								<u-row style="margin-top: 20px;">
									<u-col span="4">
										车牌号:
									</u-col>
									<u-col span="6">
										{{item.plateNo}}
									</u-col>
									<u-col span="2">

										<u-button type="primary" size="mini" style="width: 100rpx;  "
											@click="userCarDelete(item.plateNo)">
											删除</u-button>
									</u-col>
								</u-row>
								<u-row style="margin-top: 10px;">
									<u-col span="4">
										登记时间:
									</u-col>
									<u-col span="12">
										<view v-if="item.lastTime!=null">{{item.lastTime}}</view>
										<view v-if="item.lastTime==null">{{item.createTime}}</view>
									</u-col>
								</u-row>
							</view>

						</u-radio>
					</u-radio-group>

					<view v-if="total!=0">
						<pagination :total="total" :page-size="data.pageSize" :current-page="pageNo"
							@page-change="handlePageChange" />

					</view>
				</view>


			</scroll-view>

		</u-modal>
		<u-picker :show="showFunction" @confirm="functionConfirm" @cancel="showFunction = false" keyName="text"
			:columns="FunctionColumns">
		</u-picker>
	</view>
</template>

<script>
	import {
		getAction,
		postAction,
		putAction
	} from '@/api/api.js';
	import config from '@/api/config.js'
	import Pagination from '@/components/Pagination.vue'

	export default {
		components: {
			Pagination
		},
		data() {
			return {
				tongyi: '',
				plateNo: '',
				plateList: [],
				userInfo: {
					driverName: '',
					phoneNum: '',
					idCard: '',
					openId: '',
					engineNum: '',
					carBrandModel: '',
					carType: '',
					carType1: '',
					plateNo: '',
					evnType1: '',
					evnType: ''

				},
				carDis: false,
				vinDis: true,
				fileList99: [],
				total: 0,
				fileList3: [],
				rules: {
					'producedTime': {
						type: 'string',
						required: true,
						message: '请选择车辆生产设施',
						trigger: ['blur', 'change']
					},
					'remarks': {
						type: 'string',
						required: true,
						message: '请输入备注',
						trigger: ['blur', 'change']
					},
					'fleet': {
						type: 'string',
						required: true,
						message: '请输入运输公司营业执照名称',
						trigger: ['blur', 'change']
					},
					'engineType': {
						type: 'string',
						required: true,
						message: '请输入发动机型号',
						trigger: ['blur', 'change']
					},
					'engineManufacturer': {
						type: 'string',
						required: true,
						message: '请输入发动机制造商名称',
						trigger: ['blur', 'change']
					},
					'networkingStatus': {
						type: 'string',
						required: true,
						message: '请选择联网状态',
						trigger: ['blur', 'change']
					},
					'fuelType': {
						type: 'string',
						required: true,
						message: '请选择燃料类型',
						trigger: ['blur', 'change']
					},
					'function': {
						type: 'string',
						required: true,
						message: '请选择使用性质',
						trigger: ['blur', 'change']
					},

					'location': {
						type: 'string',
						required: true,
						message: '报道位置为空，请重新扫码上传',
						trigger: ['blur', 'change']
					},
					'transportStatus': {
						type: 'string',
						required: true,
						message: '请选择运输状态',
						trigger: ['blur', 'change']
					},

					'driverName': {
						type: 'string',
						required: true,
						message: '请填写司机姓名',
						trigger: ['blur', 'change']
					},
					'contactDept': {
						type: 'string',
						required: true,
						message: '请输入报备部门及项目',
						trigger: ['blur', 'change']
					},
					'freightVolume': {
						type: 'string',
						required: true,
						message: '请填写运输量',
						trigger: ['blur', 'change']
					},
					'goods': {
						type: 'string',
						required: true,
						message: '请输入运输内容',
						trigger: ['blur', 'change']
					},
					'leadingEnterprise': {
						type: 'string',
						required: true,
						message: '请选择引领性企业',
						trigger: ['blur', 'change']
					},
					'contactPhone': {
						type: 'string',
						required: true,
						min: 11,
						max: 11,
						message: '请输入联络人联系方式',
						trigger: ['blur', 'change']
					},
					'contactCompany': {
						type: 'string',
						required: true,
						message: '请输入报备单位',
						trigger: ['blur', 'change']
					},
					'packagingOil': {
						type: 'string',
						required: true,
						message: '请选择运输货物类型',
						trigger: ['blur', 'change']
					},
					'idCard': {
						type: 'string',
						required: true,
						message: '请选择车辆信息',
						trigger: ['blur', 'change']
					},
					'contactPerson': {
						type: 'string',
						required: true,
						message: '请输入联络人',
						trigger: ['blur', 'change']
					},
					'phoneNum': [{
						type: 'string',
						required: true,
						message: '请填写手机号码',
						trigger: ['blur', 'change']
					}, {
						type: 'string',
						required: true,
						min: 11,
						max: 11,
						message: '请填写11手机号码',
						trigger: ['blur', 'change']
					}],
					'idCard': [{
							type: 'string',
							required: true,
							message: '请填写身份证号',
							trigger: ['blur', 'change']
						},
						{
							type: 'string',
							required: true,
							min: 18,
							max: 18,
							message: '请填写18位身份证号',
							trigger: ['blur', 'change']
						}
					],
				},
				fieldDisplay: {},
				addLoading: false,
				urls: {
					addUser: '/personnelInformation/personnelInformation/m/add',
					editUser: '/personnelInformation/personnelInformation/m/edit',
					carRegister: '/carRegister/carRegister/m/register',
					getUserByOpenId: '/carRegister/carRegister/m/getUserByOpenId',
					getCarByOpenId: '/carRegister/carRegister/m/getCarByOpenId',
					getGoodsUrl: '/carRegister/carRegister/m/getGoods',
					start: '/api/vin/start',
					submit: '/api/vin/submit',
					refreshCaptcha: '/api/vin/refreshCaptcha',
					cleanup: '/api/vin/cleanup',
					//查询车辆类型字典
					car_type_url: '/sys/dict/getDictItems/car_type',
					//查询燃料类型
					fuel_type_url: '/sys/dict/getDictItems/fuel_type',
					//查询使用性质
					function_url: '/sys/dict/getDictItems/function',
					//查询拜访类型
					evn_type_url: '/sys/dict/getDictItems/evn_type',
					getPlateUrl: '/carInformation/carInformation/m/queryByPlate',
				},
				location: '',
				openId: '',
				showRemarks: '',
				carMessage: {},
				carShow: false,
				plateList: [],
				data: {
					openId: '',
					pageSize: 10,
				},
				title: "选择车辆信息",
				pageNo: 1,
				selectIndex: '',
				FunctionColumns: [],
				showFunction: false,
				src: '',
				fileList2: [],


			}
		},
		onLoad() {
			this.fieldDisplay = uni.getStorageSync("fieldDisplay")
			this.openId = uni.getStorageSync("openId")
			this.data.openId = this.openId

			this.getMessage()
			//this.start()


		},
		onHide() {
			this.cleanup()
		},
		methods: {
			userCarDelete(plate) {
				let url = '/carPersonnel/carPersonnel/m/delete?openId=' + this.model.userInfo.openId + "&plateNo=" + plate
				delAction(url).then(res => {
					console.log(res);
					if (res.success) {
						this.getCarList()
					}
				})


			},
			addCarMessage() {
				this.carShow = false
				this.carClear()
			},
			carClear(res) {
				this.carDis = false
				this.driversLicenseDel = false
				this.plateChange()
				this.userInfo.carType = ""
				this.userInfo.carType1 = ""
				this.userInfo.evnType = ""
				this.userInfo.evnType1 = ""
				this.userInfo.fleet = ""
				this.userInfo.fuelType = ""
				this.userInfo.fuelType1 = ""
				this.userInfo.function = ""
				this.userInfo.function1 = ""
				this.userInfo.networkingStatus = ""
				this.userInfo.networkingStatus1 = ""
				this.userInfo.plateColor = ""
				this.userInfo.plateNo = ""
				this.userInfo.plateNo = ""
				this.userInfo.registerDate = ""
				this.userInfo.producedTime = ""
				this.userInfo.vin = ""
				this.userInfo.carBrandModel = ""
				this.userInfo.engineNum = ""

				this.fileList2 = []
				this.fileList3 = []
				this.fileList99 = []
				this.userInfo.license = ""
				this.userInfo.inventory = ""
				this.userInfo.driversLicense = ""
				this.userInfo.engineType = ""
				this.userInfo.engineManufacturer = ''

			},
			getMessage() {
				this.userInfo.location = uni.getStorageSync("location")
				this.userInfo.leadingEnterprise = uni.getStorageSync("leadingEnterprise")
				this.userInfo.openId = this.openId
				this.getUser()
				this.getCarList(1)

			},
			carConfirm() {

				if (Object.keys(this.carMessage).length == 0) return uni.$u.toast("请选择车辆信息");
				this.carShow = false
				this.carRendering(this.carMessage)
			},
			carRendering(res) {


				this.carDis = true

				this.fileList2 = []

				this.fileList99 = []


				this.userInfo.carType = res.carType
				this.userInfo.carType1 = res.carType
				this.userInfo.engineNum = res.engineNum
				this.userInfo.evnType = res.evnType
				this.userInfo.evnType1 = res.evnType_dictText
				this.userInfo.fuelType = res.fuelType
				this.userInfo.fuelType1 = res.fuelType_dictText
				this.userInfo.fleet = res.fleet
				this.userInfo.fuelType = res.fuelType
				this.userInfo.function = res.function
				this.userInfo.function1 = res.function_dictText
				this.userInfo.networkingStatus = res.networkingStatus
				this.userInfo.networkingStatus1 = res.networkingStatus_dictText
				this.userInfo.plateColor = res.plateColor
				this.userInfo.plateNo = res.plateNo

				this.userInfo.registerDate = res.registerDate
				this.userInfo.producedTime = res.producedTime
				this.userInfo.vin = res.vin
				this.userInfo.carBrandModel = res.carBrandModel
				this.userInfo.engineType = res.engineType
				this.userInfo.engineManufacturer = res.engineManufacturer

				this.userInfo.license = res.license
				this.userInfo.inventory = res.inventory
				this.fileList2.push({
					url: res.inventory,
					aurl: res.inventory
				})

				this.fileList99.push({
					url: res.license,
					aurl: res.license
				})
			},
			getCarList(data) {
				this.plateList = []
				this.total = 0
				this.data.pageNo = this.pageNo
				if (this.data.pageNo == 0) {
					this.data.pageNo == 1
				}
				getAction(this.urls.getCarByOpenId, this.data).then(res => {
					if (res.success && res.result.records.length > 0) {
						this.total = res.result.total
						this.plateList = res.result.records
						if (data == 1) {
							this.carRendering(res.result.records[0])
						}

					}
				})
			},
			handlePageChange(page) {
				this.pageNo = page;
				this.getCarList()
			},
			addInfo() {
				this.$refs.uForm.validate().then(res => {
					if (!this.tongyi) {
						return uni.showToast({
							icon: "error",
							title: "请同意，上传信息真实准确"
						})
					}
					let licenseArr = [];
					let inventoryArr = [];
					if (this.fileList99.length == 0) {
						return uni.$u.toast("请上传行驶证照片")
					}
					if (!this.fileList99[0].aurl) {
						return uni.$u.toast("请等待行驶证上传完毕")
					}
					if (this.fileList2.length === 0) {
						return uni.$u.toast("请上传环保清单照片")
					}

					if (!this.fileList2[0].aurl) {
						return uni.$u.toast("请等待环保清单上传完毕")
					}


					this.fileList99.forEach(item => {
						licenseArr.push(item.aurl)
					})
					this.fileList2.forEach(item => {
						inventoryArr.push(item.aurl)
					})

					this.model.userInfo.license = licenseArr + "";
					this.model.userInfo.inventory = inventoryArr + "";
					if (this.fieldDisplay.driversLicense == 1) {
						if (this.fileList3.length === 0) {
							return uni.$u.toast("请上传驾驶证")
						}
						if (!this.fileList3[0].aurl) {
							return uni.$u.toast("请等待驾驶证上传完毕")
						}
						this.userInfo.driversLicense = this.fileList3[0].aurl;
					};

					//新增

					this.addLoading = true
					postAction(this.urls.carRegister, this.userInfo).then((res) => {
						this.clearCar()
						if (res.success) {
							if (res.result.success) {
								uni.showModal({
									title: '提示',
									content: res.message,
									showCancel: false,
									success: (res1) => {
										if (res1.confirm) {
											this.cleanForm();
											if (res.result.message == "请进行司机培训") {

												this.pageto1()
											}
										}
									}
								});
							} else {
								uni.showModal({
									title: '提示',
									content: res.result.message,
									showCancel: false,
									success: (res1) => {
										if (res1.confirm) {


										}
									}
								});
							}
						} else {

							uni.showModal({
								title: '提示',
								content: "添加失败，请联系管理员",
								showCancel: false,
								success: (res1) => {
									if (res1.confirm) {


									}
								}
							});
						}


					})

					this.addLoading = false
				}).catch((res) => {
					uni.showModal({
						title: '提示',
						content: res[0].message,
						showCancel: false,
						success: (res) => {
							if (res.confirm) {

							}
						}
					});
				})
			},
			getCarPlate() {
				this.pageNo = 1
				this.data.plateNo = this.plateNo
				this.getCarList(2)


			},
			clearCar() {
				this.$refs.uForm.resetFields();
				this.getMessage()
				this.userInfo.evnType1 = ""
			},
			getUser() {
				getAction(this.urls.getUserByOpenId, {
					openId: this.openId
				}).then(res => {
					if (res.success && res.result) {
						this.fileList3 = []

						this.userInfo.driverName = res.result.driverName
						this.userInfo.phoneNum = res.result.phoneNum
						this.userInfo.idCard = res.result.idCard
						this.fileList3.push({
							url: res.result.driversLicense,
							aurl: res.result.driversLicense
						})
					}
				})
			},
			async afterRead(event) { // 新增图片
				// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					await this.uploadFilePromise(lists[i].url, event.name).then((result) => {
						let item = this[`fileList${event.name}`][fileListLen]
						this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
							status: 'success',
							message: '',
							aurl: result.message
						}))
						fileListLen++
						if (event.name == 99) {
							this.userInfo.engineNum = ""
							this.userInfo.carBrandModel = ""
							this.userInfo.carType = ""
							this.userInfo.carType1 = ""
							this.userInfo.plateNo = ""
							this.userInfo.registerDate = ""
							this.userInfo.vin = ""
							if ((this.userInfo.plateColor == 0 || this.userInfo.plateColor == 1) &&
								result.result.plate.length == 8) {
								this[`fileList${event.name}`] = [];
								return uni.$u.toast("车牌颜色与实际车辆不符")


							}
							if (this.userInfo.plateColor == 4 && result.result.plate.length == 7) {
								this[`fileList${event.name}`] = [];
								return uni.$u.toast("车牌颜色与实际车辆不符")

							}

							this.getPlateNo(result)
						}
					})
				}
			},
			handleInput(event) {

				// 获取输入值  
				let value = event;
				value = value.replace(/[^a-zA-Z0-9]/g, '').toLowerCase().replace(/[a-z]/g, function(char) {
					return char.toUpperCase();
				});
				// 更新绑定值  
				this.userInfo.engineNum = value;


			},
			getPlateNo(result) {
				console.log(result);
				getAction(this.urls.getPlateUrl, {
					plate: result.result.plate
				}).then(res => {

					if (res.success && res.result.records.length > 0) {
						this.carRendering(res.result.records[0])
						if (!this.plateList.some(item => item.plateNo === res.result.records[0].plateNo)) {
							this.plateList.push(res.result.records[0]);
						}
					} else {
						/* 		uni.showModal({
									title: '提示',
									content: "请检查车辆信息是否正确",
									showCancel: false,
								
								}); */
						let dateStr = result.result.registerDate

						this.userInfo.engineNum = result.result.engineNum
						this.userInfo.carBrandModel = result.result.carBrandModel
						this.userInfo.carType = result.result.carType
						this.userInfo.carType1 = result.result.carType
						this.userInfo.plateNo = result.result.plate
						this.userInfo.registerDate = dateStr.slice(0, 4) + "-" + dateStr.slice(4, 6)
							.padStart(2, '0') + "-" + dateStr.slice(6, 8).padStart(2, '0')
						this.userInfo.vin = result.result.vin
						if (this.userInfo.plateNo.length == 8) {
							this.userInfo.evnType1 = "电动"
							this.userInfo.evnType = "D"

						}
						const now = new Date();
						const hours = now.getHours(); // 获取当前小时
						const minutes = now.getMinutes(); // 获取当前分钟


						const startHour = 20;
						const endHour = 7;
						if (hours >= startHour || (hours < endHour && (hours !== 0 || minutes !== 0))) {
							this.vinDis=false
						} else {
							this.start()
						}



					}
				})
			},
			deletePic(event) { // 删除图片
				if (event.name == 99) {
					this.userInfo.engineNum = ""
					this.userInfo.carBrandModel = ""
					this.userInfo.carType = ""
					this.userInfo.carType1 = ""
					this.userInfo.plateNo = ""
					this.userInfo.registerDate = ""
					this.userInfo.vin = ""
				}
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			uploadFilePromise(url, name) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: config.baseUrl + config.imgUpload,
						filePath: url,
						name: 'file',
						formData: {
							name: name

						},
						success: (res) => {
							let result = JSON.parse(res.data)
							if (result.success) {
								setTimeout(() => {
									resolve(result)
								}, 100)
							} else {
								reject(result)
							}
						}
					});
				})
			},
			radioChangeGoods(e) {
				this.userInfo.goods = ""
				this.userInfo.goods1 = ""
				this.showRemarks = false
				this.userInfo.remarks = ""
				if (this.rules.userInfo && this.rules.userInfo.remarks) {
					this.$delete(this.rules.userInfo, 'remarks');
				}
			},
			selectCarShow() {
				this.carShow = true
				this.carMessage = {}
			},
			radioChange(e) {
				this.carMessage = e
			},
			getCarType(e) {

				this.FunctionColumns = []
				this.selectIndex = e
				//运输货物名称
				if (e == 5) {
					this.userInfo.goods = ""
					this.userInfo.goods1 = ""
					if (this.userInfo.leadingEnterprise == null || this.userInfo.leadingEnterprise.length == 0)
						return uni.$u.toast("请选择引领性");
					if (this.userInfo.transportStatus == null || this.userInfo.transportStatus.length == 0) {
						return uni.$u.toast("请选择提货或者送货");
					} else {
						getAction(this.urls.getGoodsUrl, {
							location: this.userInfo.location,
							transportStatus: this.userInfo.transportStatus,
							leadingEnterprise: this.userInfo.leadingEnterprise
						}).then(res => {
							if (res.success) {
								let temp = []
								res.result.result.forEach(e => {
									let re = {
										value: e,
										text: e,
										title: e
									}
									temp.push(re)
								})
								this.FunctionColumns.push(temp)
								this.showFunction = true
							} else {
								return uni.$u.toast(res.message)
							}
						})
					}
				}
				if (e == 1) {
					getAction(this.urls.car_type_url).then(res => {
						if (res.success) {
							this.showFunction = true
							this.FunctionColumns.push(res.result)
						}
					})
				}
				//燃料类型
				if (e == 2) {
					getAction(this.urls.fuel_type_url).then(res => {
						if (res.success) {
							this.showFunction = true
							this.FunctionColumns.push(res.result)
						} else {
							return uni.$u.toast(res.message)
						}
					})
				}
				//使用性质
				if (e == 3) {
					getAction(this.urls.function_url).then(res => {


						if (res.success) {
							this.showFunction = true
							this.FunctionColumns.push(res.result)
						} else {
							return uni.$u.toast(res.message)
						}

					})
				}
				//排放类型
				if (e == 4) {
					getAction(this.urls.evn_type_url).then(res => {
						if (res.success) {
							this.showFunction = true
							this.FunctionColumns.push(res.result)
						} else {
							return uni.$u.toast(res.message)
						}
					})
				}

			},
			//选择器确认按钮
			functionConfirm(e) {

				//车辆类型
				if (this.selectIndex == 1) {
					this.userInfo.carType1 = e.value[0].text
					this.userInfo.carType = e.value[0].value
					this.showFunction = false

				}
				//燃料类型
				if (this.selectIndex == 2) {
					this.userInfo.fuelType1 = e.value[0].text
					this.userInfo.fuelType = e.value[0].value
					this.showFunction = false

				}
				//使用性质
				if (this.selectIndex == 3) {
					this.userInfo.function1 = e.value[0].text
					this.userInfo.function = e.value[0].value

					this.showFunction = false

				}
				//排放类型
				if (this.selectIndex == 4) {
					this.userInfo.evnType = e.value[0].value
					this.userInfo.evnType1 = e.value[0].text
					this.showFunction = false

				}


				//运输货物名称
				if (this.selectIndex == 5) {
					if ((e.value[0].text == "其他" || e.value[0].text == "其它") && this.fieldDisplay.remarks == 1) {
						this.showRemarks = true
						this.$set(this.rules, 'userInfo.remarks', [{
							type: 'string',
							required: true,
							message: '请输入备注',
							trigger: ['blur', 'change']
						}]);
					} else {
						this.showRemarks = false
						this.userInfo.remarks = ""

						if (this.rules.userInfo && this.rules.userInfo.remarks) {
							this.$delete(this.rules.userInfo, 'remarks');
						}
					}
					this.userInfo.goods1 = e.value[0].text
					this.userInfo.goods = e.value[0].value

					this.showFunction = false

				}

			},
			//vin关闭按钮
			cleanup() {

				let params = "?openId=" + this.openId
				postAction(this.urls.cleanup + params).then((res) => {
					if (!res.success) {
						this.cleanup()
					}
				})
			},
			//获取验证码
			start() {
				if (!this.carDis && !this.vinDis) return
			

				let params = "?openId=" + this.openId 
				getAction(this.urls.start + params).then((
						res) => {
						if (res.success) {
							this.src = config.baseUrl + "/" + res.result
						}
					})
					.catch(res => {
						this.start()
					})
			},
			//刷新验证码
			refreshCaptcha() {
				let params = "?openId=" + this.openId
				postAction(this.urls.refreshCaptcha + params).then((res) => {
					if (res.success) {
						this.src = config.baseUrl + "/" + res.result
					}
				})
			},
			beforeChooseColor() {

				if (!this.userInfo.plateColor) {
					uni.showModal({
						title: '提示',
						content: "请选择车牌颜色",
						showCancel: false,

					});
					return false;
				} else {
					return true;
				}

			},
			plateChange(e) {
				if (e === "4") {
					this.plateColor = "green"
					this.plateInput = ""
					this.PageCur = 2
					this.plateNo = '';
					this.userInfo.evnType = "新能源"
				} else {
					this.userInfo.evnType = ""
					this.PageCur = 1
					this.plateNo = '';
					this.plateInput = "xinnengyuan"
					if (e === "0") {
						this.plateColor = "blue"
					} else {
						this.plateColor = "yellow"
					}
				}
			},

			query() {
				if (!this.userInfo.captcha) return uni.$u.toast("请输入验证码")
				if(!this.userInfo.vin||this.userInfo.vin.length!=17)return uni.$u.toast("请检查vin码")
				this.addLoading = true
				let params = "?openId=" + this.openId + "&captcha=" + this.userInfo.captcha + "&vin=" + this.userInfo.vin + "&engine=" + this.userInfo.engineNum
				postAction(this.urls.submit + params).then((res) => {
					this.addLoading = false

					if (res.success) {
						if (res.result.error) {

							this.refreshCaptcha()

							return uni.$u.toast(res.result.error)
						} else {
							this.userInfo.carBrand = res.result.carBrand
							this.userInfo.carModel = res.result.carModel
							this.userInfo.engineManufacturer = res.result.engineManufacturer
							this.userInfo.engineType = res.result.engineType
							this.userInfo.evnType = res.result.evnType
							this.userInfo.evnType1 = res.result.evnType_dictText


							this.vinDis = false
							this.cleanup()
						}
					} else {
						this.start()
					}
				})
			}

		}
	}
</script>

<style>
	.login-view {
		width: 100%;
		position: relative;
		background-color: #ffffff;
		border-radius: 8% 8% 0% 0;
	}
</style>
